
clear
set more off
set type double, perm


use ${wd}/cps/CPSextract.dta,clear

* keep age 20-65
keep if age>=20&age<=65

* keep those with non-negative potential experience
*gen temp  = age - yearsch_1 - 6
gen temp = min(age-yearsch_2-6, age-16)
drop if temp<0
drop temp


* keep observations with positive weights
keep if wgt>0

g union=union_mem

preserve
	keep if year<=1985
	ren smsarank smsa
	do "${cps}/programs/smsa_city_cw.do"
	replace city=. if city==0
	save ${wd}/cps/fullCPS.dta,replace
restore

preserve
	keep if year>=1986 & year<=1988
	g city=.
	do "${cps}/programs/cmsa_msa_xwalk.do"
	do "${cps}/programs/msa_city_cw.do"
	append using ${wd}/cps/fullCPS.dta
	save ${wd}/cps/fullCPS.dta,replace
restore

preserve
	keep if year>1988 & year<=2003
	g city=.
	do "${cps}/programs/msa_city_cw.do"
	append using ${wd}/cps/fullCPS.dta
	save ${wd}/cps/fullCPS.dta,replace
restore


keep if year>2003
g msa=.
g city=.
do "${cps}/programs/cbsa_city_xwalk.do"
drop if state==22 & city!=4 // New Jersey drop. CBSA too problematic
append using ${wd}/cps/fullCPS.dta
save ${wd}/cps/fullCPS.dta,replace


do "${cps}/programs/labels_state.do"
do "${cps}/programs/labels_city_final.do"
label val state state
label val city city

// education recode to match Census
replace educ=4 if educ==5
g educ2=educ
recode educ2 (2=1) (3=2) (4=3)

drop wage
g wage=lnwkw_cpi

keep   year msa city state county detind majind ind_des ind_90 wage union union_* empl unem nilf hrw_cpi lnhrw_cpi hrw_ppi lnhrw_ppi hrw_pce lnhrw_pce lnwkw_cpi female black educ wgt fwt lswt hours ///
	pexp pexp2 hispanic age yearsch_1 yearsch_2 married  lfstat empl unem nilf earnsamp class alloc  ///
	intmonth hrsample serial hhid hrhhid2 hhnum lineno minsamp race untype
	
save ${wd}/cps/fullCPS.dta,replace

******************
*For May extracts
******************
use ${wd}/cps/CPSMay,clear

keep if year>1973 & year<1983

keep if age>=20&age<=65

g smsa=x11
drop x11
g state=x7
drop x7
g union=union_mem
drop union_mem

do "${cps}/programs/smsa_city_cw.do"
do "${cps}/programs/labels_state.do"
do "${cps}/programs/labels_city_final.do"
label val state state
label val city city

// education recode to match Census
replace educ=4 if educ==5
g educ2=educ
recode educ2 (2=1) (3=2) (4=3)

drop wage
g wage=lnwkw_cpi

* keep those with non-negative potential experience
*gen temp  = age - yearsch_1 - 6
gen temp = min(age-yearsch_2-6, age-16)
drop if temp<0
drop temp


* keep observations with positive weights
keep if wgt>0

keep year city smsa state detind majind ind_des ind_90 wage union* empl unem nilf hrw_cpi lnhrw_cpi hrw_ppi lnhrw_ppi hrw_pce lnhrw_pce lnwkw_cpi female black educ wgt fwt lswt ///
	pexp pexp2 hispanic age yearsch_1 yearsch_2 married  lfstat empl unem nilf earnsamp class alloc ///
	 cluster segment  serial hhid  hhnum  race month 
	 
tostring hhid, replace
tostring serial, replace

save ${wd}/cps/fullCPS1980.dta,replace
append using ${wd}/cps/fullCPS.dta
save ${wd}/cps/fullCPS.dta,replace




label define untype_lbl 1 "Job loser/on layoff" ///
2 "Other job loser" ///
3 "Temporary job ended" ///
4 "Job leaver" ///
5 "Re-entrant" ///
6 "New-entrant"

label values untype untype_lbl



